package cn.zjitc.service.impl;

import cn.zjitc.dao.UserBookDao;
import cn.zjitc.entity.PageResult;
import cn.zjitc.entity.QueryPageBean;
import cn.zjitc.pojo.Book;
import cn.zjitc.pojo.Borrow;
import cn.zjitc.pojo.History;
import cn.zjitc.service.UserBookService;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service(interfaceClass = UserBookService.class)
@Transactional
public class UserBookServiceImpl implements UserBookService {
    @Autowired
    private UserBookDao userBookDao;

    @Override
    public List<Book> findAll() {
        return userBookDao.findAll();
    }

    @Override
    public Book findById(Integer id) {
        return userBookDao.findById(id);
    }

    @Override
    public PageResult pageQuery(QueryPageBean queryPageBean) {
        Integer currentPage = queryPageBean.getCurrentPage();
        Integer pageSize = queryPageBean.getPageSize();
        String queryString = queryPageBean.getQueryString();

        PageHelper.startPage(currentPage,pageSize);
        Page<Book> page = userBookDao.findByCondition(queryString);
        long total = page.getTotal();
        List<Book> rows = page.getResult();
        return new PageResult(total,rows);
    }

    @Override
    public void add(Borrow borrow) {
        userBookDao.add(borrow);
    }

    @Override
    public Integer getendtime(Integer userId) {
        return userBookDao.getendtime(userId);
    }

    @Override
    public Integer findremainnum(Integer id) {
        return userBookDao.findremainnum(id);
    }

    @Override
    public void editbooklist(Integer id) {
        userBookDao.editbooklist(id);
    }

    @Override
    public void edituserborrow(Integer user_id) {
        userBookDao.edituserborrow(user_id);
    }

    @Override
    public void addHistory(History history) {
        userBookDao.addHistory(history);
    }

}
